package cn.com.bluemoon.daps.standard.mapper;

import cn.com.bluemoon.daps.standard.entity.DapStandardBasicDic;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 基础标准-字典代码表 Mapper 接口
 * </p>
 *
 * @author admin
 * @since 2020-08-03
 */
public interface DapStandardBasicDicMapper extends BaseMapper<DapStandardBasicDic> {

    @Select("SELECT\n" +
            "       a.standard_unique_id,\n" +
            "       b.id,\n" +
            "       b.base_code,\n" +
            "       b.base_code_name,\n" +
            "       b.base_remark,\n" +
            "       b.basic_standard_id,\n" +
            "       b.business_define,\n" +
            "       b.code_name,\n" +
            "       b.code_value,\n" +
            "       b.create_by,\n" +
            "       b.create_time,\n" +
            "       b.update_by,\n" +
            "       b.update_time,\n" +
            "       b.bm_status\n" +
            "FROM dap_standard_basic a\n" +
            "left join dap_standard_basic_dic b on a.id = b.basic_standard_id\n" +
            "WHERE a.bm_status = 1 and b.bm_status = 1\n" +
            "  AND b.basic_standard_id <> #{standardBasicId} \n" +
            "  and a.standard_unique_id <> #{standardUniqueId} \n" +
            "  AND (b.base_code_name = #{baseCodeName} OR b.base_code = #{baseCode} )")
    List<Map<String, Object>> findDuplicateBaseCode(@Param("baseCode") String baseCode,
                                                    @Param("baseCodeName") String baseCodeName,
                                                    @Param("standardBasicId") String standardBasicId,
                                                    @Param("standardUniqueId") String standardUniqueId);

    @Select("select distinct b.base_code_name, b.base_code from dap_standard_basic_dic b where 1=1 and b.bm_status = 1")
    List<Map<String, Object>> findDuplicateBaseCodeForImport(@Param("baseCode") String baseCode,
                                                    @Param("baseCodeName") String baseCodeName);

    @Select("SELECT\n" +
            "       a.standard_unique_id,\n" +
            "       b.id,\n" +
            "       b.base_code,\n" +
            "       b.base_code_name,\n" +
            "       b.base_remark,\n" +
            "       b.basic_standard_id,\n" +
            "       b.business_define,\n" +
            "       b.code_name,\n" +
            "       b.code_value,\n" +
            "       b.create_by,\n" +
            "       b.create_time,\n" +
            "       b.update_by,\n" +
            "       b.update_time,\n" +
            "       b.bm_status\n" +
            "FROM dap_standard_basic a\n" +
            "left join dap_standard_basic_dic b on a.id = b.basic_standard_id\n" +
            "WHERE a.bm_status = 1 and b.bm_status = 1\n" +
            "  AND b.basic_standard_id <> #{standardBasicId} \n" +
            "  AND (b.base_code_name = #{baseCodeName} OR b.base_code = #{baseCode} )")
    List<Map<String, Object>> findDuplicateBaseCodeStandardUniqueIdIsNull(@Param("baseCode") String baseCode,
                                                    @Param("baseCodeName") String baseCodeName,
                                                    @Param("standardBasicId") String standardBasicId);
}
